<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改步骤')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-step-edit" th:object="${recipeDishStep}">
            <input name="stepId" th:field="*{stepId}" type="hidden">
            <input name="dishId" th:field="*{dishId}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">步骤描述：</label>
                    <div class="col-sm-8">
                        <textarea name="stepDesc" th:field="*{stepDesc}" class="form-control" required></textarea>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">步骤图片：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="hidden" name="stepPic" id="pic" th:field="*{stepPic}" required>
                    <a id="url"><img style="width: 90px;height: 90px" th:src="*{stepPic}"></a>
                    <input type="file" id="stepPic">
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">步骤顺序：</label>
                    <div class="col-sm-8">
                        <input name="stepSort" th:field="*{stepSort}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                        <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "recipe/step";
        $("#form-step-edit").validate({
            focusCleanup: true
        });

        // 上传文件
        $("#stepPic").change(function () {
            var data = new FormData();
            data.append("file", $("#stepPic")[0].files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    // alert(JSON.stringify(result))
                    if (result.code == web_status.SUCCESS) {
                        $("#url img").attr("src",result.fileName)
                        $("#pic").val(result.fileName)
                    }
                },
                error: function(error) {
                    alert("图片上传失败。");
                }
            });
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-step-edit').serialize());
            }
        }
    </script>
</body>
</html>